package com.by.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ServivE
 * @version 0.1
 * @className OrderController
 * @description
 * @date 2024/10/28 19:20
 * @since jdk17
 */
@RestController
@RequestMapping("/api")
public class OrderController {

    @Value("${service.goods}")
    String goodsService;
    @Autowired
    RestTemplate restTemplate;


    @PostMapping("/order")
    public String save() {
        System.out.println("生成订单");
        //更新库存
        Map<String, Integer> map = new HashMap<>();
        map.put("goodsId", 1);
        map.put("num", 10);
        String rs = restTemplate.getForObject(goodsService + "/api/goods?goodsId={goodsId}&num={num}", String.class, map);
//        String rs = restTemplate.getForObject("http://localhost:7000/api/goods?goodsId={goodsId}&num={num}", String.class, map);
        System.out.println("更新库存: " + rs);
        return "success";
    }
}
